import { fromJS } from 'immutable';
import * as constants from './constants';

// current: 分页当前页码
// isLoading: pagination
// workCheckData: 待审核作品数据
// dialogVisible: 对话框是否显示 boolean
// dialogData: 动态
// dialogTags: 标签
const defaultState = fromJS({
  current: 1,
  isLoading: false,
  workCheckData: [],
  dialogVisible: false,
  dialogData: [],
  dialogTags: ""
});

export default (state = defaultState, action) => {
  switch(action.type) {
    case constants.GET_WORKCHECKDATA:
      return state.set("workCheckData", fromJS(action.workCheckData));
    case constants.OPEN_DIALOG:
      return state.merge({
        dialogVisible: true,
        dialogData: fromJS(action.dialogData),
        dialogTags: fromJS(action.dialogTags)
      });
    case constants.CLOSE_DIALOG:
      return state.set("dialogVisible", false);
    case constants.WORK_PASS:
      return state.set("dialogVisible", false);
    case constants.WORK_REJECT:
      return state.set("dialogVisible", false);
    default:
      return state;
  }
}